package com.trade.wzj.service.xiang;


import javax.annotation.Resource;

import org.springframework.stereotype.Service;

import com.trade.wzj.dao.xiang.ClientAdd;
import com.trade.wzj.model.xiang.ClientInfo;

@Service("ClientAddService")
public class ClientAddimpl implements ClientAddService {
	@Resource
	private ClientAdd mapper;

	public ClientAdd getMapper() {
		return mapper;
	}

	public void setMapper(ClientAdd mapper) {
		this.mapper = mapper;
	}
	/*
	 * (non-Javadoc)客户基础信息添加
	 * @see com.trade.wzj.service.xiang.ClientAddService#AddClient(com.trade.wzj.model.xiang.ClientInfo)
	 */
	@Override
	public boolean AddClient(ClientInfo info) throws Exception{
		String name = info.getClientName();
		ClientInfo list = mapper.SelClient(name);

		if (info.getClientAddress().equals("") || info.getClientAddress()==null  && list != null) {
			try {
				throw new Exception("不能为空");
			} catch (Exception e) {
				e.printStackTrace();
			}
		} else if (info.getClientContacts().equals("")) {
			try {
				throw new Exception("不能为空");
			} catch (Exception e) {
				e.printStackTrace();
			}
		} else if (info.getClientEmail().equals("")) {
			try {
				throw new Exception("不能为空");
			} catch (Exception e) {
				e.printStackTrace();
			}
		} else if (info.getClientFax().equals("")) {
			try {
				throw new Exception("不能为空");
			} catch (Exception e) {
				e.printStackTrace();
			}
		} else if (info.getClientName().equals("")) {
			try {
				throw new Exception("不能为空");
			} catch (Exception e) {
				e.printStackTrace();
			}
		} else if (info.getClientPhone().equals("")) {
			try {
				throw new Exception("不能为空");
			} catch (Exception e) {
				e.printStackTrace();
			}

		} else {
			int result = mapper.AddClient(info);

			if (result > 0) {
				System.out.println("messafe" + "该信息已存在，请重新输入");
				return false;
			}
		}
		return true;
	}
	/*
	 * (non-Javadoc)客户显示
	 * @see com.trade.wzj.service.xiang.ClientAddService#SelClient(java.lang.String)
	 */
	@Override
	public ClientInfo SelClient(String name) throws Exception{
		ClientInfo lise = null;
		try {
			lise = mapper.SelClient(name);
		} catch (Exception e) {
			e.printStackTrace();
		}
		return lise;
	}

}